<template>
	<view class="content">
		<view class="list">
			<view class="ul2" v-for="(item,index) in order.orderItems">
			    <view class="li"><image :src="baseUrl + item.thumbnail"></image></view>
			    <view class="li">
			        <view class="name">{{item.name}}</view>
			        <view class="zl">重量：{{item.weight}}g</view>
			    </view>
			    <view class="li">¥{{item.price}}</view>
			    <view class="li">x{{item.quantity}}</view>
			    <view class="li">￥{{item.totalPrice}}</view>
			</view>
		</view>
		<view class="list">
			<view class="item">
				<view class="left">评论 </view>
				<textarea v-model="form.reviewEntryList[0].review.content" placeholder="您有什么想要说明的..."></textarea>
			</view>
		</view>
		<view class="list">
			<view class="item">
				<view class="left">图片信息 </view>
				<view class="right pics">
					<view class="box" @click="delPic(index)" v-for="item,index in imgList" :key="index">
						<image class="pic" :src="baseUrl + item"></image>
						<view class="del-box"><!-- <image class="del" src="../../static/images/29-29.png"></image> --></view>
					</view>
					<image class="add" @click="goAdd" src="@/static/images/92.png"></image>
				</view>
			</view>
		</view>
		
		<view class="submit-btn" @click="submit">提交</view>
	</view>
</template>

<script>
	import {
		orderDetail
	} from '@/api/order.js'
	import {
		reviewSave
	} from '@/api/user.js'
	import urlConfig from '@/common/config.js'
	export default {
		data() {
			return {
				sn: '',
				id: '',
				imgList: [],
				baseUrl: this.$baseUrl,
				order: {},
				item: {},
				form: {
					orderId: '',
					reviewEntryList: [
						{
							orderItem: {
								id: ''
							},
							review: {
								score: 5,
								content: '',
								images: ''
							},
						}
					]
				}
			}
		},
		onLoad(options) {
			this.sn = options.sn
			this.id = parseInt(options.id)
			// this.form.orderId = this.id
			this.form.reviewEntryList[0].orderItem.id = this.id
			this.init()
		},
		methods: {
			init() {
				orderDetail({orderSn: this.sn}).then(res => {
					this.order = res.data.order
					this.form.orderId = this.order.id
					this.order.orderItems.some(r => {
						if(r.id === this.id) {
							this.item = r
							return true
						}
					})
				})
			},
			goAdd() {
				let that = this
				uni.chooseImage({
					count: 1,
					success: res => {
						uni.uploadFile({
							url: urlConfig + '/public/file',
							filePath: res.tempFilePaths[0],
							name: 'file',
							success: (inner) => {
								try {
									let str = JSON.parse(inner.data)
									that.imgList.push(str.data.url)
								} catch (err) {
									uni.showToast({
										title: err,
										icon: 'none'
									})
								}
							}
						})
					}
				})
			},
			delPic(index) {
				this.imgList.splice(index, 1)
			},
			submit() {
				this.imgList.forEach(r => {
					this.form.reviewEntryList[0].review.images += r + ';'
				})
				reviewSave(JSON.stringify(this.form)).then(res => {
					uni.showToast({
						title: res.message,
						icon: 'none'
					})
					setTimeout(() => {
						uni.navigateTo({
							url: '/pages/comment/list'
						})
					}, 800)
				})
			}
		}
	}
</script>

<style lang="less">
.content {
	padding-bottom: 30rpx;
	background-color: #F8F9FA;
	min-height: 100vh;
}
.submit-btn {
	line-height: 80rpx;
	text-align: center;
	border-radius: 80rpx;
	color: #fff;
	background-color: #D30500;
	margin: 40rpx 30rpx 0;
}
label {
	display: inline-block;
	margin-left: 30rpx;
}
.list {
	padding: 30rpx;
	margin-top: 30rpx;
	background-color: #fff;
}

.list .item {
	display: flex;
	align-items: top;
	justify-content: space-between;
	color: #1a1a1a;
}

.list .item.center {
	align-items: center;
}

.left {
	width: 130rpx;
	margin-right: 20rpx;
}

.trackNo {
	width: calc(100% - 160rpx);
}

textarea {
	height: 200rpx;
	padding: 0;
	margin: 0;
}

.list .pics {
	width: calc(100% - 160rpx);
}

.list .box {
	margin: 0 15rpx 15rpx 0;
	position: relative;
	width: 150rpx;
	height: 150rpx;
	display: inline-block;
}

.list image {
	width: 150rpx;
	height: 150rpx;
}

.list .del-box {
	background: url(~@/static/images/29-29.png) no-repeat center rgba(255, 255, 255, .8);
	background-size: 60%;
	width: 45rpx;
	height: 45rpx;
	position: absolute;
	top: 0;
	right: 0;
}

.bottom_total {
		display: flex;
		align-items: center;
		justify-content: space-between;
		height: 110rpx;
		width: 100%;
		background-color: #ffffff;
		position: fixed;
		bottom: 0;
		left: 0;
		z-index: 99999;

		.left {
			padding-left: 30rpx;

			text {
				color: #b81c22;
				font-size: 32rpx;
			}
		}

		.right {
			color: #ffffff;
			letter-spacing: 4rpx;
			width: 300rpx;
			text-align: center;
			height: 110rpx;
			line-height: 110rpx;
			background-color: #b81c22;
		}
	}

.ul2 {
    /* border: 1px solid #EDEDED; */
    background-color: #fff;
    display: flex;
    align-items: center;
}

.ul2 .li:nth-child(1) image {
    margin-right: 20rpx;
	width: 120rpx;
	height: 120rpx;
}

.ul2 .li:nth-child(2) view:nth-child(2) {
    color: #999;
	padding-top: 15rpx;
    /* font-size: 14rpx; */
}

.ul2 .li:nth-child(3) {
    flex-grow: 4;
    text-align: center;
    /* font-size: 14rpx; */
    padding: 0 20rpx;
}

.ul2 .li:nth-child(4) {
    flex-grow: 2;
    padding: 0 20rpx;
    /* font-size: 14rpx; */
}


.ul2 .li:nth-child(5) {
    /* font-size: 14rpx; */
    color: #D30500;
}
</style>
